#ifndef DEVICEMAP_H
#define DEVICEMAP_H

#include <QWidget>
#include <QMouseEvent>//鼠标事件
#include <QPainter>
#include <QLabel>
#include <QDebug>
namespace Ui {
class deviceMap;
}

class deviceMap : public QWidget
{
    Q_OBJECT

public:
    explicit deviceMap(QWidget *parent = 0);
    explicit deviceMap(QWidget *parent,int row,int x ,int y );
    ~deviceMap();
    //重写鼠标点击窗口的触发函数
    void mousePressEvent(QMouseEvent *event) override;
    int x;
    int y;
    int row;

    //重写画图事件
    void paintEvent(QPaintEvent *event) override {
        //画线
        if(x!=-1){
            QPainter painter(this);
            painter.setRenderHint(QPainter::Antialiasing);

            // 获取窗口的宽度和高度
            int width = this->width();
            int height = this->height();

            // 设置线条的颜色和宽度
            QPen pen(Qt::red, 2); // 黑色，宽度为2
            painter.setPen(pen);

            // 绘制一条从窗口左边到右边的水平线，位于窗口高度的中间
            painter.drawLine(0, y, width, y);
            painter.drawLine(x, 0, x, height);
        }
    }
signals:
    void signal_return_A(int row, int x, int y);


private slots:
    void on_pushButton_clicked();

    void on_pushButton_2_clicked();

private:
    Ui::deviceMap *ui;
};

/*
class myLabel: public deviceMap,public QFrame
{
    Q_OBJECT
public:
    int x;
    int y;

    myLabel(QWidget *parent = 0):deviceMap(parent),QFrame(parent)
    {

    }
    //重写鼠标点击窗口的触发函数
    void mousePressEvent(QMouseEvent *event) override{
        qDebug()<<"鼠标事件触发:"<<event->x()<<","<<event->y();

        QString value=QString("%1,%2").arg(event->x()).arg(event->y());
        //ui->label_2->setText(value);

        this->x=event->x();
        this->y=event->y();

        if(x!=-1){
            QPainter painter(this);
            painter.setRenderHint(QPainter::Antialiasing);

            // 获取窗口的宽度和高度
            int width = this->width();
            int height = this->height();

            // 设置线条的颜色和宽度
            QPen pen(Qt::red, 2); // 黑色，宽度为2
            painter.setPen(pen);

            // 绘制一条从窗口左边到右边的水平线，位于窗口高度的中间
            painter.drawLine(0, y, width, y);
            painter.drawLine(x, 0, x, height);
        }

    }

    //重写画图事件
    void paintEvent(QPaintEvent *event) override {
        //画线
        if(x!=-1){
            QPainter painter(this);
            painter.setRenderHint(QPainter::Antialiasing);

            // 获取窗口的宽度和高度
            int width = this->width();
            int height = this->height();

            // 设置线条的颜色和宽度
            QPen pen(Qt::black, 2); // 黑色，宽度为2
            painter.setPen(pen);

            // 绘制一条从窗口左边到右边的水平线，位于窗口高度的中间
            painter.drawLine(0, y, width, y);
            painter.drawLine(x, 0, x, height);
        }
    }
};
*/

#endif // DEVICEMAP_H
